package cn.openea.perpartner.componet.rabbit.service.impl.sms;

import cn.hutool.core.bean.BeanUtil;
import cn.openea.perpartner.common.core.enums.RabbitEnums;
import cn.openea.perpartner.componet.web.entity.dto.sms.SmsDto;
import cn.openea.perpartner.componet.web.enums.ScopeEnums;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Weird077
 * @description TODO
 * @date 2023-05-25 12:09
 */
@Slf4j
@Service
public class AliyunSmsPublisher {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    public boolean batchSendMsgToMeilyUser(SmsDto dto) {
        String exchange = RabbitEnums.MEILY_BUSINESS.getExchange();
        String routeKey = RabbitEnums.MEILY_BUSINESS.getRoutingKey();
        if (BeanUtil.isEmpty(dto)) {
            return false;
        }
        JSONObject object = new JSONObject();
        object.put("beanName", ScopeEnums.getBeanName(dto.getSendScope()));
        object.put("params", JSON.toJSON(dto));
        rabbitTemplate.convertAndSend(exchange, routeKey, object, message -> {
            message.getMessageProperties().setHeader("x-delay", 0);
            return message;
        });
        log.info("发送消息：{}", object);
        return true;
    }

}
